package cs342.project1.mathNotebook.data;

import cs342.project1.mathNotebook.data.*;
import cs342.project1.mathNotebook.notebook.NotebookEntry;
import cs342.project1.mathNotebook.notebook.NotebookEntryListModel;
import cs342.project1.mathNotebook.notebook.SlopeTable;

import java.util.ArrayList;
import java.util.List;
import java.util.Collection;

public class XMLNotebook implements NotebookInterface {
	
	String filename;
	
	public XMLNotebook(String filename){
		this.filename = filename;
	}
	
	public void saveNotebook(Collection<NotebookEntry> entries){
		NotebookWriter writer = new XMLNotebookRepositoryFactory(this.filename).createWriter();
        writer.writeAll(entries);
        writer.close();
	}
	
	public List<NotebookEntry> loadNotebook(String name){
		List<NotebookEntry> notebookEntries = new ArrayList<NotebookEntry>();
		NotebookReader reader = new XMLNotebookRepositoryFactory(filename).createReader();
		notebookEntries = reader.getAll();
		reader.close();		
		return notebookEntries;
	}
	
}